$('document').ready(function(){     
    resize();
    $(window).resize(function(){                          
        resize();   
    });            
    var widthOfWin = $(window).width();
    var widthOfMess = $('.message').width();
    var left = (widthOfWin - widthOfMess)/2;
    $('.message').css({"left":left});
    
    $('.message-close').click(function(){
        $('.message').hide();
    });
    
    $('.menu-left ul li').click(function(){
        var item = $(this).next("li").find("ul");
        if(item == null){return;}
        if(item.is(':hidden')){                  
            item.show();                         
        }else{                
            item.hide();
        }               
    });
    
    $('#bottom').append("<div class='backtop'></div>");
    $('.backtop').hide();
    $(window).scroll(function(){
    	if($(window).scrollTop() != 0){
    		$('.backtop').fadeIn();
    	}else{
    		$('.backtop').fadeOut();
    	}
    });
    $('.backtop').click(function(){
    	$('html,body').animate({scrollTop:0},300);
    });
                         
    jQuery.fn.center = function () {
	    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
	    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
	    return this;
	};
    $('.popup-confirm').draggable(); 
    
    $('.main-content-table .cbx').click(function(){
        if($(this).is(':checked')){                
            $(this).parent().parent().addClass("table-row-selected");                 
        }else{                    
            $(this).parent().parent().removeClass("table-row-selected");
        }               
    });
});

function openConfirmPopup(){
	$('.wrap-popup-confirm').show();
	$('.popup-confirm').center();
	return false;
}
function closeConfirmPopup(){
	$('.wrap-popup-confirm').hide();
	return false;
}	

function acceptConfirmPopup(){
	$('.wrap-popup-confirm').hide();
	return true;
}	

function loading(){
	$('.loading').css({"visibility":"visible"});
}

function closeLoading(){
	$('.loading').css({"visibility":"hidden"});
}

function resize(){ 
	var widthOfWin = $(window).width(); // width of browser
	var heightOfWin = $(window).height(); // height of browser
	
	var heightTop = $('#top').height(); // width top
	var heightBottom = $('#bottom').height(); // width bottom
	    
    var heightOfMiddle = (heightOfWin - (heightTop + heightBottom + 80));      
    var widthLeft = $('#lcontent').width(); // width of left content (menu left)
    var widthRight = widthOfWin - widthLeft - 10; // get width of right content from width of left content
        
    $('#rcontent').css({"width":widthRight});  // set width for right content             
    //$('.rcontent-main').css({"height":heightOfMiddle});  // set height for right content main   
    var newHeightOfMiddle = $('#rcontent').height();
    //$('#lcontent').css({"height":newHeightOfMiddle}); // set height for left content
    
    var widthOfMess = $('.message').width(); // get width of message
    var left = (widthOfWin - widthOfMess)/2; // set margin for message
    $('.message').css({"left":left}); // set css for message
}